﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using LogicaNegocio;
using Entidades;
namespace PresentacionEscritorio
{
    public partial class frmAgregarPracticasEnHc : Form
    {
        private GestorHistorialClinicos gHC = new GestorHistorialClinicos();
        public frmAgregarPracticasEnHc()
        {
            InitializeComponent();
            crearGrilla();
            cargarPracticasMedicas();

        }

        private void cargarPracticasMedicas()
        {
            List<Practica> lsp = gHC.obtenerPracticasMedicas();
            foreach (Practica practica in lsp)
            {
                int i = dtgAgregarPracticas.Rows.Add();
                dtgAgregarPracticas.Rows[i].Cells["Practica"].Value = practica.nombre;
                dtgAgregarPracticas.Rows[i].Cells["idPractica"].Value = practica.codigo;
            }
        }
        private void crearGrilla()
        {
            dtgAgregarPracticas.Columns.Add("Practica", "Practica");
            dtgAgregarPracticas.Columns["Practica"].ReadOnly = true;
            dtgAgregarPracticas.Columns.Add("idPractica", "idPractica");
            dtgAgregarPracticas.Columns["idPractica"].Visible = false;
            DataGridViewCheckBoxColumn seleccionar = new DataGridViewCheckBoxColumn();
            seleccionar.HeaderText = "seleccionar";
            seleccionar.Name = "seleccionar";


            dtgAgregarPracticas.Columns.Add(seleccionar);

        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            List<Practica> lstp = new List<Practica>();
            Practica p = null;
            DialogResult r = MessageBox.Show("¿Desea agregar las practicas a realizar?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (r == DialogResult.Yes)
            {
                for (int i = 0; i < dtgAgregarPracticas.Rows.Count; i++)
                {

                    if (dtgAgregarPracticas.Rows[i].Cells["seleccionar"].Value != null)
                    {
                        p = new Practica();
                        p.codigo = int.Parse(dtgAgregarPracticas.Rows[i].Cells["idPractica"].Value.ToString());
                        p.nombre = dtgAgregarPracticas.Rows[i].Cells["Practica"].Value.ToString();
                        lstp.Add(p);
                        p = null;
                    }

                }
                IPractica iparent = this.Owner as IPractica;
                iparent.AddPracticas(lstp);
                this.Close();
            }

        }

        private void frmAgregarPracticasEnHc_Load(object sender, EventArgs e)
        {

        }








    }
}
